package com.hlt.controller.user;

import com.hlt.dto.FollowsPageQueryDTO;
import com.hlt.result.PageResult;
import com.hlt.result.Result;
import com.hlt.service.IFollowsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lzf
 * @since 2024-11-25
 */
@RestController
@RequestMapping("/users/follows")
@Api(tags = "用户关注接口")
@Slf4j
public class FollowsController {

    @Resource
    private IFollowsService followsService;

    // 关注接口
    @PostMapping
    @ApiOperation("关注接口")
    public Result follow(@RequestParam Long followingId) {
        log.info("关注接口，被关注用户ID：{}", followingId);
        // 调用服务层方法进行关注操作
        followsService.follow(followingId);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("取消关注接口")
    public Result unfollow(@RequestParam Long followingId) {
        log.info("取消关注接口，被关注用户ID：{}", followingId);
        followsService.unfollow(followingId);
        return Result.success();
    }

    @GetMapping("/following/{userId}")
    @ApiOperation("获取指定用户的关注列表")
    public Result<PageResult> getFollowingList(
            @PathVariable Long userId,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("获取用户关注列表，用户ID：{}", userId);
        FollowsPageQueryDTO pageQueryDTO = new FollowsPageQueryDTO();
        pageQueryDTO.setUserId(userId);
        pageQueryDTO.setPageNum(pageNum);
        pageQueryDTO.setPageSize(pageSize);
        PageResult pageResult = followsService.getFollowingList(pageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/followers/{userId}")
    @ApiOperation("获取指定用户的粉丝列表")
    public Result<PageResult> getFollowersList(
            @PathVariable Long userId,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("获取用户粉丝列表，用户ID：{}", userId);
        FollowsPageQueryDTO pageQueryDTO = new FollowsPageQueryDTO();
        pageQueryDTO.setUserId(userId);
        pageQueryDTO.setPageNum(pageNum);
        pageQueryDTO.setPageSize(pageSize);
        PageResult pageResult = followsService.getFollowersList(pageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/following")
    @ApiOperation("获取当前用户的关注列表")
    public Result<PageResult> getCurrentUserFollowingList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("获取当前用户关注列表");
        FollowsPageQueryDTO pageQueryDTO = new FollowsPageQueryDTO();
        pageQueryDTO.setPageNum(pageNum);
        pageQueryDTO.setPageSize(pageSize);
        PageResult pageResult = followsService.getCurrentUserFollowingList(pageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/followers")
    @ApiOperation("获取当前用户的粉丝列表")
    public Result<PageResult> getCurrentUserFollowersList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("获取当前用户粉丝列表");
        FollowsPageQueryDTO pageQueryDTO = new FollowsPageQueryDTO();
        pageQueryDTO.setPageNum(pageNum);
        pageQueryDTO.setPageSize(pageSize);
        PageResult pageResult = followsService.getCurrentUserFollowersList(pageQueryDTO);
        return Result.success(pageResult);
    }
}
